structure T = Tokens

type lexresult = Tokens.token
type pos = int

val lineNum = ref 0
val linePos = ref [0]
  
val eof = (fn () => Tokens.EOF)

fun str2int str = let val result=Int.fromString str 
		     in 
			 case result of SOME i => i 
				      | NONE => 0
		     end 

%%
%posarg
%s COMMENT LCOMMENT;
digit=[0-9];
ws=[\ \t];

%%

<INITIAL>{ws}+ 	        => (continue());
<INITIAL>"->"           => (T.ARROW(yypos));

<INITIAL>"/*"		=> (YYBEGIN COMMENT; continue());
<INITIAL>"//"		=> (YYBEGIN LCOMMENT; continue());
<COMMENT>"*/"		=> (YYBEGIN INITIAL; continue());
<LCOMMENT>"\n"		=> (YYBEGIN INITIAL; lineNum := !lineNum+1; linePos := yypos :: !linePos; continue());
<COMMENT>"\n"		=> (lineNum := !lineNum+1; linePos := yypos :: !linePos; continue());
<COMMENT,LCOMMENT>.	=> (continue());


<INITIAL>{digit}+	=> (T.INTCONST(str2int yytext,yypos));
<INITIAL>.       	=> (print ("Invalid character: "^yytext^"\n"); continue());
